<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>json</title>
</head>
<body>
</body>
<script>

    /* json
    *  数组
    *     变异操作 --- √
    *     非变异操作
    * */

     var arr = [0];
     var arr2 =[1,2];

    console.log("arr的长度是:"+arr.length);
    console.log("arr2的长度是:"+arr2.length);


    arr.push(23);
    arr.pop();
    console.log(arr);

    arr.unshift(45);
    arr.unshift(453);
    arr.shift();
    console.log(arr);

    arr[1]= 67;
    console.log(arr);

    for(var i=0;i<arr.length;i++){ // for-i
      console.log(arr[i]);
    }

    for(var key in arr){ //for-in
        console.log(key+':'+arr[key]);
    }


    /**
     *  json 对象
     * */

    /**
     *  使用不同的对象，来表示不同的业务实体
     * */
    var student = {
        name:'Mat',
        gender:'male',
        age:23
    }

    student.age = 34;
    //业务逻辑错误
    console.log("age:"+student.name);

    console.log("name:"+student.name);
    console.log("name:"+student['name']);

    for (var kay  in student ){
         console.log(kay+':'+student[kay]);
    }

    /**
     *  json 数组
     * */

    var employees = [
        {
            name:'Mat',
            age:23
        },{
            name: 'Mary',
            age:34
        }
    ]

    employees.push({name:'Tea',age:45});


</script>
</html>